package com.itheima.hashmap;

import java.util.HashMap;
import java.util.function.BiConsumer;

public class A01_HashMapDemo1 {
    public static void main(String[] args) {
        /*需求
        创建一个HashMap集合，键是学生对象(Student)，值是籍贯(String)。
        存储三个键值对元素，并遍历
        要求：同姓名，同年龄认为是同一个学生*/
        HashMap<Student,String> hashMap = new HashMap<>();
        Student s1 = new Student("zhangsan",23);
        Student s2 = new Student("lisi",24);
        Student s3 = new Student("wangwu",25);
        Student s4 = new Student("lisi",24);

        hashMap.put(s1,"长沙");
        hashMap.put(s2,"上海");
        hashMap.put(s3,"北京");
        hashMap.put(s4,"武汉");

        hashMap.forEach(new BiConsumer<Student, String>() {
            @Override
            public void accept(Student student, String s) {
                System.out.println(student.getName()+", "+student.getAge()+", "+s);
            }
        });
    }
}
